﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Manager_Nguoidung_Controls_UC_Khachhang : System.Web.UI.UserControl
{
    BUS_Customers customer = new BUS_Customers();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();
        }
    }
    public void LoadData()
    {
        gvQuanly.DataSource = customer.Customers_GetByAll();
        gvQuanly.DataBind();
    }
    public string Trangthai(bool tr)
    {

        if (tr)
        {
            return "Hoạt động";
        }
        else
        {
            return "Đã khóa";
        }
    }
    protected void gvQuanly_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Chitiet")
        {
            Response.Redirect("Chitietnguoidung.aspx?khachhang=" + e.CommandArgument);
        }
        if (e.CommandName == "Xoa")
        {
            customer.Customers_Delete(e.CommandArgument.ToString());
            Response.Redirect(Request.RawUrl);
        }
    }
    protected void btnTimkiem_Click(object sender, EventArgs e)
    {
        var dt = customer.Customers_GetByTop(0, "UserName like '%" + txtUserName.Text + "%'and Mail like '%" + txtEmail.Text + "%'and FullName like '%" + txtFullName.Text + "%' and Address like '%" + txtAddress.Text + "%'", "");
        Literal1.Text = "<div class='ketquatimkiem'>Có "+dt.Rows.Count+" kết quả được tìm thấy.</div>";
        gvQuanly.DataSource = dt;
        gvQuanly.DataBind();
    }
    protected void gvQuanly_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvQuanly.PageIndex = e.NewPageIndex;
        LoadData();
    }
}